package com.common.jms;

import java.util.HashMap;
import java.util.Map;

import javax.jms.Destination;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;

import com.lab.account.domain.User;

/**
 * JMS用户变更消息生产者.
 * 
 * 使用jmsTemplate将用户变更消息分别发送到queue与topic.
 * 
 * @author calvin
 */
//@Service
public class NotifyMessageProducer {

	@Autowired
	private JmsTemplate jmsTemplate;
	@Autowired
	private Destination notifyQueue;
	@Autowired
	private Destination notifyTopic;

	public void sendQueue(User user) {
		sendMessage(user, notifyQueue);
	}

	public void sendTopic(User user) {
		sendMessage(user, notifyTopic);
	}

	private void sendMessage(User user, Destination destination) {
		Map map = new HashMap();
		map.put("username", user.getUsername());
		map.put("email", user.getEmail());

		jmsTemplate.convertAndSend(destination, map);
	}
}
